package CtrLayer;

import java.util.ArrayList;

import ModelLayer.OrderCollection;
import ModelLayer.Product;
import ModelLayer.Stock;

/**
 * Write a description of class StockCtr here. CONTROL LAYER OF STOCK
 * 
 * @author (Georgi Georgiev)
 * @version (11.12.2013)
 */
public class StockCtr
{

	/**
	 * Constructor for objects of class StockCtr
	 */
	public StockCtr()
	{

	}

	/*********************************************************** ADDING METHOD ***************************************************************/

	/**
	 * Method in which the CtrLayer passes information from the ModelLayer to
	 * the UILayer.
	 */
	public boolean add_product(String name, String category, String department,
			double price, double price_for_palette, int pieces_in_palette,
			int quantity, int maximum_amount, int minimum_amount,
			int amount_qualified_for_discount, String group_nr, double discount)
	{
		return Stock.add_product(name, category, department, price,
				price_for_palette, pieces_in_palette, quantity, maximum_amount,
				minimum_amount, amount_qualified_for_discount, group_nr,
				discount);
	}

	/*********************************************************** FINDING METHODS ***************************************************************/

	/**
	 * This method takes name of a product as an input and returns it's articule
	 * number.
	 */
	
	public String get_next_art_nr()
	{
		return Stock.get_next_art_nr();
	}
	
	public String[] give_string_array(String art_nr)
	{
		return Stock.find_product_by_art_nr(art_nr).give_string_data().split("\t");
	}
	
	public String get_art_nr_via_name(String name)
	{
		return Stock.get_art_nr_via_name(name);
	}
	
	public String get_name_via_art_nr(String art_nr)
	{
		return Stock.get_name_via_art_nr(art_nr);
	}

	/**
	 * Methods in which the CtrLayer fidns information(Product by it's articule
	 * number) from the ModelLayer,converts it to Object[] and passes it to the
	 * UILayer.
	 */
	public Object[] find_product_by_art_nr(String i_art_nr, boolean needs_restocking, boolean is_unfinished)
	{
		Product var = Stock.find_product_by_art_nr(i_art_nr);
		if (var != null)
		{
			if (var.is_unfinished() == is_unfinished && !(!(var.needs_restocking()) && needs_restocking))
			{
				return var.give_array();
			}
			
		}
		return null;
	}

	/**
	 * Methods in which the CtrLayer finds information(Product by it's name)
	 * from the ModelLayer, converts it to Object[] and passes it to the UILayer.
	 */
	public Object[] find_product_by_name(String i_name, boolean needs_restocking, boolean is_unfinished)
	{
		Product var = Stock.find_product_by_name(i_name);
		if (var != null)
		{
			if (var.is_unfinished() == is_unfinished && !(!(var.needs_restocking()) && needs_restocking))
			{
				return var.give_array();
			}
		}
		return null;
	}

	/**
	 * Method to find products from the same category.
	 */
	public String find_products_by_category(String i_category)
	{
		ArrayList<Product> var = Stock.find_products_by_category(i_category);
		String var2 = "";
		for (Product var3 : var)
		{
			var2 = var2 + "\n" + var3.printable();
		}
		return var2;
	}
	
	public Object[] provide_sales_line_item_data(String art_nr, int quantity)
	{
		return Stock.provide_sales_line_item_data(art_nr, quantity);
	}
	
	public double get_sales_line_item_cost(Object[] data)
	{
		return Stock.get_sales_line_item_cost((String) data[0], (Integer) data[1]);
	}
	
	public Object[][] display_all_products()
	{
		return Stock.display_all_products();
	}

	public Object[][] display_unfinished_products()
	{
		return Stock.display_unfinished_products();
	}

	public Object[][] display_products_that_need_restocking()
	{
		return Stock.display_products_that_need_restocking();
	}

	public String display_by_group_nr(String group_nr)
	{
		return Stock.display_by_group_nr(group_nr);
	}

	/*********************************************************** EDITING METHODS ***************************************************************/

	/**
	 * Method to change product's name.
	 */
	public void edit_name(String art_nr, String name)
	{
		Stock.edit_name(art_nr, name);
	}

	/**
	 * Method to change product's category.
	 */
	public void edit_category(String art_nr, String category)
	{
		Stock.edit_category(art_nr, category);
	}

	/**
	 * Method to change product's department.
	 */
	public void edit_department(String art_nr, String department)
	{
		Stock.edit_department(art_nr, department);
	}

	/**
	 * Method to change product's price.
	 */
	public boolean edit_price(String art_nr, double price)
	{
		return Stock.edit_price(art_nr, price);
	}

	/**
	 * Method to change product's price for palette.
	 */
	public boolean edit_price_for_palette(String art_nr,
			double price_for_palette)
	{
		return Stock.edit_price_for_palette(art_nr, price_for_palette);
	}

	/**
	 * Method to change the amount of products in a palette.
	 */
	public void edit_pieces_in_palette(String art_nr, int pieces_in_palette)
	{
		Stock.edit_pieces_in_palette(art_nr, pieces_in_palette);
	}

	/**
	 * Method to change product's quatity
	 */
	public boolean edit_quantity(String art_nr, int quantity)
	{
		return Stock.edit_quantity(art_nr, quantity);
	}

	/**
	 * Method to change product's maximum amount in stock(warehouse).
	 */
	public boolean edit_maximum_amount(String art_nr, int maximum_amount)
	{
		return Stock.edit_maximum_amount(art_nr, maximum_amount);
	}

	/**
	 * Method to change product's minimum amount in stock(warehouse).
	 */
	public boolean edit_minimum_amount(String art_nr, int minimum_amount)
	{
		return Stock.edit_minimum_amount(art_nr, minimum_amount);
	}

	/**
	 * Method to change the amount of products required to get a discount.
	 */
	public boolean edit_amount_qualified_for_discount(String art_nr,
			int amount_qualified_for_discount)
	{
		return Stock.edit_amount_qualified_for_discount(art_nr,
				amount_qualified_for_discount);
	}

	public void edit_group_nr(String art_nr, String group_nr)
	{
		Stock.edit_group_nr(art_nr, group_nr);
	}

	public void edit_discount(String art_nr, double discount)
	{
		Stock.edit_discount(art_nr, discount);
	}

	/*********************************************************** DELETE METHODS ***************************************************************/

	/**
	 * Method to delete a product.
	 */
	public boolean delete_product(String art_nr)
	{
		if (Stock.does_such_product_exist(art_nr))
		{
			OrderCollection.clear_product(art_nr);
			return Stock.delete_product(art_nr);
		}
		return false;
	}

	/**
	 * Method to delete a product by name.
	 */
	public boolean delete_product_by_name(String name)
	{
		if (Stock.does_such_product_exist(Stock.get_art_nr_via_name(name)))
		{
			return delete_product(Stock.get_art_nr_via_name(name));
		}
		return false;
	}

	/*********************************************************** OTHER METHODS ***************************************************************/

	/**
	 * Method to check if there is such product in the system.
	 */
	public boolean does_exist(String art_nr)
	{
		return Stock.does_such_product_exist(art_nr);
	}

	public boolean is_such_name(String name)
	{
		return Stock.is_such_name(name);
	}

	public boolean is_such_group_nr(String group_nr)
	{
		return Stock.is_such_group_nr(group_nr);
	}

	public boolean is_kitchen_bathroom_product(String art_nr)
	{
		return Stock.is_kitchen_bathroom_product(art_nr);
	}

	public boolean is_product_unfinished(String art_nr)
	{
		return Stock.is_product_unfinished(art_nr);
	}
	
	public boolean is_such_amount(String art_nr, String amount)
	{
		return Stock.is_such_amount(art_nr, amount);
	}

	/**
	 * Method to save the changes.
	 */
	public boolean save_data()
	{
		return Stock.save_data();
	}
}
